//
//  Team9BaseViewController.m
//  Team9Project
//
//  Created by 朱嘉祺 on 15/10/12.
//  Copyright © 2015年 apple. All rights reserved.
//

#import "Team9BaseViewController.h"

@interface Team9BaseViewController ()

@end

@implementation Team9BaseViewController
/*
 进行了 样式规划 夜间模式 留一个一个 刷新和占位图的工具类属性
 */

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    if (self.navigationController.viewControllers.count > 4) {
       self.navigationItem.rightBarButtonItem  = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemOrganize target:self action:@selector(popRootVC)];
    }
    self.tabBarController.tabBar.tintColor = [UIColor lightGrayColor];
}
- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changecolor) name:@"changecolor" object:nil];
    }
    return self;
}
#pragma mark 返回主页
- (void)popRootVC{
    [self.navigationController popToRootViewControllerAnimated:YES];
    self.navigationController.navigationBar.translucent = NO;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.translucent = NO;
    self.tabBarController.tabBar.translucent = NO;
    [self changecolor];
}

#pragma mark 夜间模式
- (void)changecolor{
    for (UIView *view in self.view.subviews) {
        if ([view isKindOfClass:[UITableView class]] || [view isKindOfClass:[UICollectionView class]]) {
            if ([Team9EveningType shareEvening].eveningFailling) {
                view.backgroundColor = [UIColor blackColor];
            } else view.backgroundColor = [UIColor whiteColor];
        }
    }
    UIImage *image;
    if ([Team9EveningType shareEvening].eveningFailling) {
        image = [UIImage imageNamed:@"back2"];
    } else image = [UIImage imageNamed:@"back"];
    
//    UIImage *backButtonImage = [image resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
//    [[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
//    //将返回按钮的文字position设置不在屏幕上显示
//    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake(0, 0, 32, 32);
    [backButton addTarget:self action:@selector(popVc) forControlEvents:UIControlEventTouchUpInside];
    [backButton setBackgroundImage:image forState:UIControlStateNormal];
    if (self.navigationController.viewControllers.count > 1) {
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    }
    
    if ([Team9EveningType shareEvening].eveningFailling) {
        self.view.backgroundColor = [UIColor colorWithWhite:0.15 alpha:1];
        NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIColor whiteColor]forKey:NSForegroundColorAttributeName];
        self.navigationController.navigationBar.titleTextAttributes = dic;
        self.navigationController.navigationBar.barTintColor = [UIColor colorWithWhite:0.15 alpha:1];
        self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
        self.tabBarController.tabBar.barTintColor = [UIColor blackColor];
       [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
        
    } else {
        self.view.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
        NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIColor blackColor]forKey:NSForegroundColorAttributeName];
        self.navigationController.navigationBar.titleTextAttributes = dic;
        self.navigationController.navigationBar.barTintColor = [UIColor colorWithWhite:0.95 alpha:1];
        self.navigationController.navigationBar.tintColor = [UIColor blackColor];
        self.tabBarController.tabBar.barTintColor = [UIColor whiteColor];
       [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
    }

}
#pragma mark 返回键
- (void)popVc{
    [self.navigationController popViewControllerAnimated:YES];
}






/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
